package org.ldx.lotterysystem.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.ldx.lotterysystem.dao.dataobject.PrizeDo;

import java.util.List;

@Mapper
public interface PrizeMapper {
    @Insert("insert into prize (name,description,price,image_url)" +
            "values (#{name},#{description},#{price},#{imageUrl})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    public long insert(PrizeDo prizeDo);

    @Select("select count(1) from prize")
    int getPrizeCount();
    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDo> getPrizeList(Integer offset, Integer pageSize);

    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectPrizesById(@Param("items") List<Long> ids);
    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='prizeIdList' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDo> bachPrizesById(List<Long> prizeIdList);
    @Select("select * from prize where id = #{prizeId}")
    PrizeDo selectById(Long prizeId);
}
